package org.wjw.base.util;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public class ClassUtils {
    public static List<Class> getAllClassName(String packageNames){
        String[] split = packageNames.split(",");
        List<Class> result = new ArrayList<>();
        for (String packageName : split) {
            String packagePath = packageName.replace(".","/");
            URL url = ClassLoader.getSystemResource(""); //获取classapth
            File[] files = new File(url.getPath() + packagePath)
                    .listFiles(file -> file.getName().endsWith(".class"));
            if(files == null || files.length < 1){
                continue;
            }
            for(File file : files){
                String fileName = file.getName();
                fileName = fileName.substring(0,fileName.lastIndexOf("."));
                String allName = packageName+"."+fileName;
                try {
                    result.add(Class.forName(allName));
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }
}